import Vue from 'vue'
// 防止重复点击
Vue.directive('preventReClick', {
    inserted (el, binding) {
        el.addEventListener('click', () => {
            if (!el.disabled) {
                el.disabled = true
                el.style['pointer-events'] = 'none'
                setTimeout(() => {
                    el.disabled = false
                    el.style['pointer-events'] = 'initial'
                }, binding.value || 2000)
            }
        })
    },
    unbind (el) {
        if (el.unbindEventListener) {
            el.unbindEventListener()
        }
    }
})
// 表格滚动加载
Vue.directive('loadmore', {
    bind (el, binding) {
        const selectWrap = el.querySelector('.el-table__body-wrapper')
        selectWrap.addEventListener('scroll', function () {
            let sign = 1
            const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight
            if (scrollDistance <= sign) {
                binding.value()
            }
        })
    },
    unbind (el) {
        if (el.unbindEventListener) {
            el.unbindEventListener()
        }
    }
})
